<?php
use Workerman\Worker;
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__.'/../public_config.php';
require_once __DIR__.'/auth.php';
//worker 对象
$http_worker = new Worker("http://0.0.0.0:2303");
//路由及中间件对象
$router = new AppRouter();
//加载控制器
$controller =  scandir(__DIR__.'/controller/');
foreach ($controller as $v){
    if(in_array($v,['.','..'])){
        continue;
    }
    require_once __DIR__.'/controller/'.$v;
}
// 启动进程数
$http_worker->count = 10;
$http_worker->name  = "name";
//初始化
$http_worker->onWorkerStart = function(){
    require_once __DIR__.'/../public_config.php';
    require_once __DIR__.'/../redis.php';
    require_once __DIR__.'/tools.php';
    require_once __DIR__."/../Singleton.php";
    require_once __DIR__."/../ApiError.php";
    require_once __DIR__."/../Req.php";
    require_once __DIR__."/../jwt.php";

    //ApiError::setProduct(true);//正式环境开启
    date_default_timezone_set('PRC');
    //thinkorm 配置
    \think\facade\Db::setConfig([
        'default' => "mysql",
        'connections' => [
            'mysql' => MYSQL,
        ],
    ]);
    //定时任务
//    new \Workerman\Crontab\Crontab('* 2 * * *',function (){
//
//    });
};


$http_worker->onMessage = [$router,"onClientMessage"];
Worker::$logFile = './logs/workerman_app.log';
Worker::$stdoutFile = './logs/app.log';
// 运行worker
Worker::runAll();